<template>
    <div class="k-form">
        <slot></slot>
    </div>
</template>

<script>
export default {
    props: {
        model: {
            type: Object,
            default: () => {},
        },
        rules: Object,
    },
    provide() {
        return {
            form: this,
        };
    },
    methods: {
        validate(cb) {
            const promises = this.$children
                .filter((item) => item.prop)
                .map((item) => item.validate());
            Promise.all(promises)
                .then(cb(true))
                .catch(() => cb(false));
        },
    },
};
</script>

<style lang="scss" scoped>
.k-form {
    display: inline-block;
    margin: 0 auto;
    text-align: center;
}
</style>
